package r21118.d1126;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

public class DemoList {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,20,30,40,50,60,70,80,90);
        System.out.println(list);

        //增强for循环遍历
//        System.out.println("增强For----------------");
//        for (Integer o :list){
//            if(o<60){
//                o+=60;
//            }
//            System.out.println(o);
//        }


        //集合的forEach()方法
        System.out.println("集合的forEach()方法----------------");
        list.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                for (int i = 0; i < list.size(); i++) {
                    if(list.get(i)<60){
                        list.set(i,list.get(i)+60);
                    }
                }
            }
        });
        System.out.println(list);


        //迭代器
        System.out.println("迭代器----------------");
        Iterator<Integer> it = list.iterator();
        while(it.hasNext()){
            Integer i =  it.next();
            if(i.hashCode()<60){
                list.set(it.next(),i.hashCode()+60);
            }
        }
        System.out.println(list);



        //传统for循环遍历
        System.out.println("传统for循环遍历----------------");
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i)<60){
                list.set(i,list.get(i)+60);
            }
        }
        System.out.println(list);


    }


}
